<% include header %>

<div class="ui form segment" onsubmit="return"  style="width: 60%;margin:0 auto 40px">
  <div class="field">
    <label>影视名称</label>
    <input type="text" name="videoName" placeholder="影视名称">
  </div>
  <div class="fields equal width">
    <div class="field">
      <label>影视国家</label>
      <select class="ui fluid search dropdown" name="videoCountry">
        <option value="">影视国家</option>
        <option value="中国">中国</option>
        <option value="美国">美国</option>
        <option value="英国">英国</option>
        <option value="法国">法国</option>
        <option value="日本">日本</option>
        <option value="泰国">泰国</option>
        <option value="韩国">韩国</option>
        <option value="印度">印度</option>
        <option value="其他">其他</option>
      </select>
    </div>
    <div class="six field">
      <label>影视分类</label>
      <select class="ui fluid search dropdown" name="videoClassify">
        <option value="">影视分类</option>
        <option value="电影">电影</option>
        <option value="电视剧">电视剧</option>
        <option value="综艺">综艺</option>
        <option value="动漫">动漫</option>
        <option value="纪录片">纪录片</option>
        <option value="其他">其他</option>
      </select>
    </div>
	  <div class="field">
	    <label>影视时间</label>
	    <input type="date" name="videoTime" placeholder="影视时间">
	  </div>
  </div>
 
  <div class="fields">
	  <div class="field">
     <label>影视图片</label>
	   <input type="file" name="file" multiple>
	  </div>
  </div>
  <div class="fields equal width">
    <div class="field">
      <label>影视评分</label>
      <select class="ui fluid search dropdown" name="videoStar">
        <option value="">影视评分</option>
        <option value="10.0">10.0</option>
        <option value="9.0">9.0</option>
        <option value="8.0">8.0</option>
        <option value="7.0">7.0</option>
        <option value="6.0">6.0</option>
        <option value="5.0">5.0</option>
        <option value="4.0">4.0</option>
        <option value="3.0">3.0</option>
        <option value="2.0">2.0</option>
        <option value="1.0">1.0</option>
      </select>
    </div>
	  <div class="field">
	    <label>影视时长(分钟/季)</label>
	    <input type="text" name="videoTimeLong" placeholder="影视时长">
	  </div>
    <div class="field">
      <label>影视类型</label>
      <select class="ui fluid search dropdown" name="videoType">
        <option value="">影视类型</option>
        <option value="动作">动作</option>
        <option value="喜剧">喜剧</option>
        <option value="爱情">爱情</option>
        <option value="剧情">剧情</option>
        <option value="古装">古装</option>
        <option value="历史">历史</option>
        <option value="战争">战争</option>
        <option value="科幻">科幻</option>
        <option value="惊悚">惊悚</option>
        <option value="恐怖">恐怖</option>
        <option value="冒险">冒险</option>
        <option value="纪录片">纪录片</option>
        <option value="武侠">武侠</option>
        <option value="动画">动画</option>
        <option value="犯罪">犯罪</option>
        <option value="脱口秀">脱口秀</option>
        <option value="成人">成人</option>
        <option value="儿童">儿童</option>
      </select>
    </div>
  </div>
  <div class=" fields">
  </div>
  <div class="field">
	  <div class="field">
	    <label>影视导演/演员</label>
	    <input type="text" name="videoActors" placeholder="影视导演/演员">
	  </div>
  </div>
  <div class="field">
    <label>影视描述</label>
    <textarea placeholder="影视描述" name="videoDetail"></textarea>
  </div>
  <div class="ui button submit">Submit</div>
  <div class="ui reset button">重置</div>
  <div class="ui clear button">清除提示</div>
</div>



<script>
  $(function(){
    $('select.dropdown').dropdown()
    var formdata = new FormData()
    $('input[name=file]').change(function (e) {
        console.log(e.target)
        formdata.append('file', e.target.files[0])
    })
    
    var isAllow = true
    if(!isAllow) return
    $('.ui.form')
    .form({
      inline : true,
      on  : 'blur',
      onSuccess: function () {
        isAllow = false;
        ['videoName', 'videoTime', 'videoTimeLong', 'videoActors'].forEach(function (val) {
            formdata.append(val, $('input[name=' + val + ']').val())
        });
        ['videoCountry', 'videoClassify', 'videoStar', 'videoType'].forEach(function (val) {
            formdata.append(val, $('select[name=' + val + ']').val())
        });
        formdata.append('videoDetail',$('textarea').val())
        $.ajax({
            url: '/upload',
            type: 'POST',
            cache: false,
            data: formdata,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function (data) {
                isAllow = true
                if (data.code == 200) {
                    alert('上传成功')
                    location.href = '/'
                    formdata = new FormData()
                }else{
                  alert('上传失败')  
                  formdata = new FormData()
                }
            }
        });
      }
       ,
      fields: {
        name: {
          identifier: 'videoName',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入名称！'
            }
          ]
        },
        country: {
          identifier: 'videoCountry',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入国家！'
            }
          ]
        },
        classify: {
          identifier: 'videoClassify',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入分类！'
            }
          ]
        },
        time: {
          identifier: 'videoTime',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入时间！'
            }
          ]
        },
        file: {
          identifier: 'file',
          rules: [
            {
              type   : 'empty',
              prompt : '请上传图片！'
            }
          ]
        },
        star: {
          identifier: 'videoStar',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入评分！'
            }
          ]
        },
        timelong: {
          identifier: 'videoTimeLong',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入时长！'
            }
          ]
        },
        type: {
          identifier: 'videoType',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入类型！'
            }
          ]
        },
        actors: {
          identifier: 'videoActors',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入导演和演员！'
            }
          ]
        },
        detail: {
          identifier: 'videoDetail',
          rules: [
            {
              type   : 'empty',
              prompt : '请输入描述！'
            }
          ]
        }, 
      }
    })
  ;
  })
</script>
<% include footer %>   